import { Ref } from 'vue'

export function useInputFormat() {
  function formatInt(val, preVal, replaceVal: Ref<string | number>) {
    const reg = /^[1-9]\d*$/

    if ((reg.test(val) && !isNaN(val)) || val === '') {
      replaceVal.value = val
    } else {
      replaceVal.value = preVal
    }
  }
  return {
    formatInt
  }
}
